//
//  OfficeHandler.m
//  gdemm
//
//  Created by 乔明超 on 16/5/5.
//  Copyright © 2016年 Goldencis. All rights reserved.
//

#import "OfficeHandler.h"
#import "StringUtil.h"
#import "WebViewController.h"
@implementation OfficeHandler
- (BOOL)isSupportedType:(NSString *)suffix{
    
    return  [suffix caseInsensitiveCompare:@"doc"]  == NSOrderedSame ||
            [suffix caseInsensitiveCompare:@"log"]  == NSOrderedSame ||
            [suffix caseInsensitiveCompare:@"docx"] == NSOrderedSame ||
            [suffix caseInsensitiveCompare:@"xls"]  == NSOrderedSame ||
            [suffix caseInsensitiveCompare:@"xlsx"] == NSOrderedSame ||
            [suffix caseInsensitiveCompare:@"wps"]  == NSOrderedSame ||
            [suffix caseInsensitiveCompare:@"wpt"]  == NSOrderedSame ||
            [suffix caseInsensitiveCompare:@"et"]   == NSOrderedSame ||
            [suffix caseInsensitiveCompare:@"ett"]  == NSOrderedSame ||
            [suffix caseInsensitiveCompare:@"xlt"]  == NSOrderedSame ||
            [suffix caseInsensitiveCompare:@"dot"]  == NSOrderedSame ||
            [suffix caseInsensitiveCompare:@"pot"]  == NSOrderedSame ||
            [suffix caseInsensitiveCompare:@"ppt"]  == NSOrderedSame ||
            [suffix caseInsensitiveCompare:@"html"]  == NSOrderedSame ||
            [suffix caseInsensitiveCompare:@"pptx"]  == NSOrderedSame;
    
    
}

- (UIViewController *)getControllerForFilePath:(NSString *)filePath{
    NSString *path = [self getDecryptedPath:filePath];
    if (path == nil) {
        return nil;
    }
    WebViewController  *webVc = [[WebViewController alloc]init];
    webVc.path = path;
    return webVc;
}

- (NSString *)getIconWithFileName:(NSString *)fileName enced:(BOOL)isEnced{
    NSString *icon;
    NSString *suffix = [StringUtil getSuffix:fileName];
    
    if ([suffix caseInsensitiveCompare:@"doc"] == NSOrderedSame ||
        [suffix caseInsensitiveCompare:@"docx"] == NSOrderedSame ||
        [suffix caseInsensitiveCompare:@"wps"] == NSOrderedSame ||
        [suffix caseInsensitiveCompare:@"wpt"] == NSOrderedSame ||
        [suffix caseInsensitiveCompare:@"dot"] == NSOrderedSame) {
        icon = isEnced ? @"cloudDisk_icon_doc_enced" : @"cloudDisk_icon_doc";
    }else if ([suffix caseInsensitiveCompare:@"xls"] == NSOrderedSame ||
              [suffix caseInsensitiveCompare:@"xlsx"] == NSOrderedSame ||
              [suffix caseInsensitiveCompare:@"et"] == NSOrderedSame ||
              [suffix caseInsensitiveCompare:@"ett"] == NSOrderedSame ||
              [suffix caseInsensitiveCompare:@"xlt"] == NSOrderedSame){
    
        icon = isEnced ? @"cloudDisk_icon_exc_enced" : @"cloudDisk_icon_exc";
    }else if ([suffix caseInsensitiveCompare:@"ppt"] == NSOrderedSame ||
              [suffix caseInsensitiveCompare:@"pptx"] == NSOrderedSame){
        icon = isEnced ? @"cloudDisk_icon_ppt_enced" : @"cloudDisk_icon_ppt";
    }else{
        icon = isEnced ? @"cloudDisk_icon_doc_enced" : @"cloudDisk_icon_doc";
    }
    
    return icon;
}
@end
